import numpy as np
import pandas as pd


class NN(object):
    def __init__(self):
        self.df = pd.read_csv('NN/scenic_data.csv')

    def create_dataset(self, data, n_steps):
        x, y = [], []
        for i in range(len(data) - n_steps):
            x.append(data[i:i + n_steps])
            x.append(data[i + n_steps, :18])
        return np.array(x), np.array(y)
    def get_model(self):
        n_step = 7
        data = self.df.values
        x, y = self.create_dataset(data, n_step)

        train_size = int(len(x) * 0.8)
        x_train, x_test = x[:train_size], x[:train_size]
        y_train, y_test = y[:train_size], y[:train_size]

        model = tf.keres.model.Sequential()
        model.add(tf.keres.layers.LSTM(50, activation='relu', return_sequences=True, input_shape=(n_step,x_train,x_test)))
        model.add(tf.keres.layers.LSTM(50, activation='relu'))
        model.add(tf.keres.layers.Dense(18))
        model.comile(optimizer='adam', loss='mse')
        model.fit(x_train,y_train,epochs=50,validation_data=(x_test,y_test))
        loss = model.evaluate(x_test,y_test)
        print(f'测试集损失:{loss:}')

if __name__ == '__main__':
    mu = NN()
    mu.get_model()